package com.authority.framework.base.controller;

import com.authority.framework.base.util.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;


/**
 * @program: jx
 * @description: 跳转页面控制层
 * @author: Mr.Yan
 * @create: 2018-09-19 15:59
 **/
@Controller
@RequestMapping(value = "/open")
public class JumpController {

    //  跳转 页面 公共方法  eg:/entryReport=entryReport
    //@RequiresRoles(value = {"system:user:view","system:role:view","system:menu:view"})
    @RequestMapping(value = "/{modelName}")
    public ModelAndView toEntryReport(@PathVariable String modelName,
                                      ModelAndView mv) {
        String viewName = "";
        String paramStr = "";
        //  存在参数
        if (modelName.contains("@")) {
            String[] splitURL = modelName.split("@");
            //  存在 截取
            viewName = splitURL[0];
            paramStr = splitURL[1];
            if (viewName.contains("!")) {
                viewName = viewName.replace("!", "\\");
                mv.setViewName(viewName);
            }
            //  截取^ 参数 month=xx&name=xx
            String[] paramArr = paramStr.split("&");

            for (String paramBean : paramArr) {
                //  截取^ 参数 [month=xx][name=xx]
                // 以=结尾 month=
                String[] param = paramBean.split("=");
                System.out.println(paramBean);
                if(paramBean.endsWith("=")){
                    param = (String[]) StringUtils.arrayAddLength(param,1);
                    param[1] = "";
                }
                mv.addObject(param[0], param[1]);
            }

        } else {
            viewName = modelName;
            if (viewName.contains("!")) {
                viewName = viewName.replace("!", "\\");
                mv.setViewName(viewName);
            }
        }
        return mv;
    }


}
